﻿using System.Windows;
using System.Windows.Controls;

namespace ParkSaleForAdmin.Component
{
    /// <summary>
    /// C_PasswordBox.xaml 的交互逻辑
    /// </summary>
    public partial class C_PasswordBox : UserControl
    {
        bool isshow = false;
        string pass = "";

        public string Password
        {
            get => pass;
            set
            {
                pass = value;

                if (pass.Length > 0)
                    holder.Visibility = Visibility.Collapsed;
                else
                    holder.Visibility = Visibility.Visible;
            }
        }
        public char PasswordChar
        {
            get => password.PasswordChar;
            set
            {
                password.PasswordChar = value;
            }
        }
        public string PlaceHolder
        {
            get => holder.Text;
            set
            {
                holder.Text = "  " + value;
            }
        }
        public bool IsShow
        {
            get => isshow;
            set
            {
                if (value)
                {
                    text.Visibility = Visibility.Visible;
                    password.Visibility = Visibility.Hidden;
                    text.Text = password.Password;
                }
                else
                {
                    password.Visibility = Visibility.Visible;
                    text.Visibility = Visibility.Hidden;
                    password.Password = text.Text;
                }
            }
        }

        public C_PasswordBox()
        {
            InitializeComponent();
            password.PasswordChanged += Password_PasswordChanged;
            text.TextChanged += Password_PasswordChanged;
        }

        private void Password_PasswordChanged(object sender, RoutedEventArgs e)
        {
            if (IsShow)
                Password = text.Text;
            else
                Password = password.Password;

        }
    }
}
